package com.example.programming.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;
import java.util.List;

import com.example.programming.common.Result;
import com.example.programming.sys.mapper.EduTeacherMapper;
import com.example.programming.sys.entity.EduTeacher;

import com.example.programming.common.tools.BaseController;

/**
 * <p>
 * 讲师 前端控制器 chrimer
 * </p>
 *
 * @author chrimer
 * @since 2020-09-09
 */
@RestController
@RequestMapping("/sys/eduteacher")
@CrossOrigin
public class EduTeacherController extends BaseController {
    @Autowired
    private EduTeacherMapper eduTeacherMapper;

    @GetMapping("getTeacherById/{id}")
    public Result getTeacherById(@PathVariable("id") String id) {
        EduTeacher teacher = eduTeacherMapper.selectById(id);
        Result result = new Result();
        result.setData(teacher);
        return result;
    }

    @ApiImplicitParams({
    @ApiImplicitParam(name = "pageNum",paramType = "query",value = "当前页码",required = true),
    @ApiImplicitParam(name = "pageSize",paramType = "query",value = "每页显示记录数",required = true)
    })
    @ApiOperation(value = "分页获取EduTeacher信息")
    @RequestMapping(method= RequestMethod.POST,value="/page")
    public Result page(
        Integer pageNum,
        Integer pageSize) {
        Result result = new Result();
        Page<EduTeacher> page = new Page<EduTeacher>(pageNum, pageSize);
        EduTeacher parms = new EduTeacher();
        QueryWrapper<EduTeacher> warpper = new QueryWrapper<EduTeacher>(parms);

        result.setData(eduTeacherMapper.selectPage(page, warpper));
        return result;
    }
    @ApiOperation(value = "保存修改EduTeacher信息")
    @RequestMapping(method= RequestMethod.POST,value="/save")
    public Result save(@RequestBody EduTeacher entity) {
        Result result = new Result();
        if (entity.getId() == null) {
            eduTeacherMapper.insert(entity);
        } else {
            eduTeacherMapper.updateById(entity);
        }
        return result;
    }
    @ApiOperation(value = "按id删除EduTeacher，可以传入多个id用，隔开")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "ids",paramType = "query",value = "传入的id串，用，隔开",required = true)
    })
    @RequestMapping(method= RequestMethod.DELETE,value="/delete")
    public Result delete( String ids) {
        Result result = new Result();
        List<String> deleteIds = new ArrayList<String>();
        for (String id : ids.split(",")) {
            deleteIds.add(id);
        }
        eduTeacherMapper.deleteBatchIds(deleteIds);
        return result;
    }

}
